'''
Create two pages that demonstrate the symbols available in the g.py
framework.

Key ones are (lower case unless Upper given):

     68 Upper delta
     97 alpha
     98 beta
    100 delta
    101 epsilon
    103 gamma
    108 lambda
    109 mu
    112 pi
    113 theta
    114 rho
    115 sigma
    116 tau
    119 omega
    120 xi
    121 psi
    122 zeta
    165 infinity
    176 degree
    177 +/-
    179 >=
    183 dot
    184 divide symbol
    185 not equal
    209 nabla
    215 small dot
    219 iff
    222 implies
    226 registered
    227 copyright
    228 trademark
'''
from __future__ import division
import string, sys, re
from math import pow
from g import *
from versiondec import VersionDec as vd

pyver = int(sys.version_info[0])

if pyver < 3:

    wrap_in_PJL = 0
    text_size = 0.25

    origin_x, origin_y = 0.5, 0.5
    scale_factor = 0.9

    def SetUp(file, orientation=portrait, units=inches):
        '''Convenience function to set up the drawing environment and return a
        file object to the output stream.
        '''
        ofp = open(file, "w")
        ginitialize(ofp, wrap_in_PJL)
        setOrientation(orientation, units)
        return ofp

    def Symbols(hex=0):
        push()
        translate(origin_x, origin_y)
        scale(scale_factor, scale_factor)
        move(0.5, 8.2)
        textSize(0.25)
        text("Characters available in the Symbol font")
        dx = 1.0
        dy = 0.3
        top = 7.9
        left = 0.5
        for ix in range(256):
            if ix == 92: continue
            x = ix % 10
            y = ix // 10
            move(left + dx*x, top - dy*y)
            textName(Symbol)
            textSize(text_size)
            text(chr(ix))
            move(left + dx*x + dx/6, top - dy*y)
            textName(Sans)
            textSize(text_size*0.8)
            if hex:
                text("   %02x" % ix)
            else:
                text("  %3d" % ix)
        pop()

    def Regular():
        push()
        translate(origin_x, origin_y)
        scale(scale_factor, scale_factor)
        move(0.5, 8.2)
        textSize(0.25)
        text("Characters available in the regular Sans font")
        dx = 1.0
        dy = 0.3
        top = 7.9
        left = 0.5
        textName(Sans)
        for ix in range(256):
            if ix == 92: continue
            x = ix % 10
            y = ix // 10
            move(left + dx*x, top - dy*y)
            textSize(text_size)
            text(chr(ix))
            move(left + dx*x + dx/6, top - dy*y)
            textSize(text_size*0.8)
            text("  %3d" % ix)
        pop()


    def main():
        s = SetUp(vd("out/symbols.ps"), landscape)
        Symbols(hex=1)
        newPage()
        Symbols()
        newPage()
        Regular()
        s.close()

    main()
